package com.nsoft.thickclient.trackMove.user;

import java.awt.GridLayout;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.BorderFactory;

import com.nsoft.thickclient.components.VOPropertyPasswordField;
import com.nsoft.thickclient.components.date.VoPropertyDateChooser;
import com.nsoft.thickclient.containers.VOPropertyComponentPanel;
import com.nsoft.thickclient.controller.ScreenView;
import com.nsoft.thickclient.model.VoModel;
import com.nsoft.thickclient.trackMove.intr.user.User;

public class UserView extends ScreenView<User> {
	/**
	 * serialVersionUID = 1L.
	 */
	private static final long serialVersionUID = 1L;

	private VoModel model = new VoModel(User.class);

	// private JComboBox box;

	public UserView(boolean editMode) {
		setLayout(new GridLayout(1, 2));
		VOPropertyComponentPanel leftPanel = new VOPropertyComponentPanel();
		leftPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		leftPanel.addVoTextField(model, "name", "Name", !editMode);
		leftPanel.addVoTextField(model, "login", "Login", !editMode);
		VOPropertyPasswordField passwordField1 = new VOPropertyPasswordField(
				model, "password");
		VOPropertyPasswordField passwordField2 = new VOPropertyPasswordField(
				model, "check");
		leftPanel.addComponent("Password", passwordField1);
		leftPanel.addComponent("Confirm Password", passwordField2);

		VOPropertyComponentPanel rightPanel = new VOPropertyComponentPanel();
		rightPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		String[] roles = { User.USER, User.REPORTER, User.ADMIN };
		rightPanel.addVoComboBox(roles, model, "role", "Role", !editMode);
		rightPanel.addVoDateChooser(model, "creationDate", "Creation Date",
				!editMode);
		VoPropertyDateChooser dateChooser = new VoPropertyDateChooser(model,
				"expiryDate");
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());
		calendar.set(GregorianCalendar.MONTH, calendar
				.get(GregorianCalendar.MONTH) + 1);
		dateChooser.setDate(calendar.getTime());
		rightPanel.addComponent("Password Exipiry Date", dateChooser, !editMode);
		rightPanel.addVoDateChooser(model, "passwordResetDate",
				"Password Reset Date", !editMode);

		add(leftPanel);
		add(rightPanel);
		// setLayout(new BorderLayout());
		/*
		 * VoPropertyFieldPanel panel = new VoPropertyFieldPanel();
		 * panel.setRightAlignment(GridBagConstraints.WEST); panel.setInsets(new
		 * Insets(10, 0, 5, 0)); VOPropertyTextField field = new
		 * VOPropertyTextField(model, "userName"); panel.addProperty("User
		 * Name", field); VOPropertyPasswordField pass = new
		 * VOPropertyPasswordField(model, "password");
		 * panel.addProperty("Password", pass); pass = new
		 * VOPropertyPasswordField(model, "password");
		 * panel.addProperty("Confirm password", pass); String[] items = {
		 * User.USER, User.REPORTER, User.ADMIN }; box = new JComboBox(items);
		 * panel.addProperty("User type", box); add(panel,
		 * BorderLayout.PAGE_START);
		 */
	}

	public VoModel getModel() {
		// ((User)model.getValueObject()).setRole(box.getSelectedItem().toString());
		return model;
	}

	public User getWorkingBean() {
		return (User) model.getValueObject();
	}

	public void setWorkingBean(User bean) {
		model.setValueObject(bean);

	}
}
